import re

def extract_dim_pairs(s):
    # 使用正则表达式匹配变量名及其可能包含的括号
    pattern = re.compile(r'(\w[\w\s]*\([^)]*\)|\w+):(\w[\w\s]*\([^)]*\)|\w+)')
    
    # 查找所有匹配的对
    matches = pattern.findall(s)    

    # 如果没有匹配项，返回空列表
    if not matches:
        return []
    
    # 将结果整理为所需格式
    result = []
    for match in matches:
        result.append(match[0])
        result.append(match[1])
    
    return result

def convert_dim_str(s):
    pattern = r'(\w+)\((?P<inner>(?:[^()]*|(?R))*)\)'

    match = re.search(pattern, s)

    if match:
        print("Captured word:", match.group(1))
        print("Captured inner content:", match.group('inner'))

# 示例用法
s = "f(2):x,foo(bar,3):y,z(3):a(b)"
print(extract_dim_pairs(s))  # 输出: ['f(2)', 'x', 'foo(bar)', 'y', 'z(3)', 'a(b)']


text = "your_input_text_here"
convert_dim_str(text)
